//
//  WSJLeftViewController.m
//  RunningMan
//
//  Created by Run on 16/5/21.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "WSJLeftViewController.h"
#import "WSJIdViewController.h"
#import "WSJLeftTableViewCell.h"

#import "WSJEditViewController.h"

@interface WSJLeftViewController ()<UITableViewDataSource,UITableViewDelegate,WSJIdViewControllerDelegate>
@property (strong, nonatomic)UITableView *tableView;
@property (strong, nonatomic)NSMutableArray *arr;
@property (strong, nonatomic)UIButton *loginBtn;
@property (strong, nonatomic)UIButton *editBtn;

@end

@implementation WSJLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
    self.arr = [NSMutableArray array];
    self.editBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.editBtn.frame = CGRectMake(125, 170, 70, 30);
    [self.view addSubview:self.editBtn];
    [self.editBtn setTitle:@"编辑" forState:UIControlStateNormal];
    [self.editBtn addTarget:self action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
  
}
- (void)createView{
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    imageView.image = [UIImage imageNamed:@"bac.jpg"];
    self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.loginBtn setImage:[UIImage imageNamed:@"logi.png"] forState:UIControlStateNormal];
    [self.view addSubview:self.loginBtn];
    self.loginBtn.frame = CGRectMake(125, 100, 70, 70);
    [self.loginBtn addTarget:self action:@selector(logiN) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(50, 200, 200, 250) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    self.tableView.rowHeight = 50;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.tableView registerClass:[WSJLeftTableViewCell class] forCellReuseIdentifier:@"left"];
    self.tableView.separatorStyle = NO;
    [imageView addSubview:self.tableView];
}
- (void)edit{
    WSJIdViewController *IDVC = [[WSJIdViewController alloc]init];
    [self presentViewController:IDVC animated:YES completion:^{
        
        
    }];
    IDVC.delegate = self;
    
    
    
}

- (void)logiN{
    WSJEditViewController *wsj = [[WSJEditViewController alloc]init];
   [self presentViewController:wsj animated:YES completion:^{
       
       
   }];
    
    
}
- (void)sendArr:(NSMutableArray *)arr{
    self.arr = arr;
 
    [self.tableView reloadData];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WSJLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"left" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    
    NSDictionary *dic = self.arr[indexPath.row];
    NSMutableArray *arr = [NSMutableArray array];
    for (NSString *str in [dic allValues]) {
        [arr addObject:str];
    }
    cell.fitLabel.text = arr.firstObject;
    cell.selectLabel.text = arr.lastObject;
    cell.fitLabel.textAlignment = 1;
    UIView *view = [[UIView alloc]initWithFrame:cell.frame];
    view.backgroundColor = [UIColor clearColor];
    cell.selectedBackgroundView = view;
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
